import os

from  torchvision import utils as vutils
import cv2
from PIL import Image
import numpy as np
import torch
from torch.utils.data import Dataset
from torch.utils.data import SubsetRandomSampler
from torchvision.datasets import ImageFolder
from torchvision import transforms
from preprocess.transforms import ToTensor,Compose,RandomRotate,Center_Crop,RandomAffine

class TestDataset(Dataset):
    def __init__(self, image_index_list,slide,window_size):
        # generate image path list

        self.image_index_list= image_index_list
        self.slide = slide
        self.window_size = window_size

        self.transforms = transforms.Compose([transforms.ToTensor(),])

    def __getitem__(self, index):
        index_x,index_y = self.image_index_list[index]
        region = self.slide.read_region((index_x, index_y), 0, (self.window_size, self.window_size))
        region = region.convert('RGB')


        return self.transforms(region), [index_x,index_y]

    def __len__(self):
        return len(self.image_index_list)
